package com.office.personalOffice.nameCard.nameCardList.control;


import com.office.personalOffice.personalInfo.model.TbStaff;
import com.office.personalOffice.nameCard.nameCardList.pojo.OaNamecard;
import com.office.personalOffice.nameCard.nameCardList.pojo.OaNamecardlist;
import com.office.personalOffice.nameCard.nameCardList.service.IsNameCardListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @project_name: OA
 * @description:
 * @author: LaoWang
 * @date: 2022/11/1 18:34
 */

@RequestMapping("/nameCardList")
@Controller
public class nameCardListControl {

    @Autowired
    private IsNameCardListService service;


    //拿取所有用户名片夹分类
    @RequestMapping("/getNameCardList")
    @ResponseBody
    public List<OaNamecardlist> getOaNamecardlist(OaNamecardlist oaNamecardlist, HttpSession session){
        TbStaff staff1 = (TbStaff) session.getAttribute("loginUser");
        oaNamecardlist.setNamecardlistMaillistId(staff1.getId().toString());
        oaNamecardlist.setNamecardlistUsable(1);
        return service.getOaNamecardlistByOaNamecardlist(oaNamecardlist);
    }



    //查看详情
    @RequestMapping("/getViewInfo")
    @ResponseBody
    public List<OaNamecard>  getAllNamecardByName(OaNamecardlist oaNamecardlist,HttpSession session){
        TbStaff staff1 = (TbStaff) session.getAttribute("loginUser");
        oaNamecardlist.setNamecardlistMaillistId(staff1.getId().toString());
        String namecardlistName = (String) session.getAttribute("namecardlistName");
        oaNamecardlist.setNamecardlistName(namecardlistName);
        return service.getAllNamecardByName(oaNamecardlist);
    }


    //点击查看详情时存放名片夹类名
    @RequestMapping("/setNamecardlistName")
    @ResponseBody
    public String  setNamecardlistName(@RequestBody OaNamecardlist oaNamecardlist,HttpSession session){
        session.setAttribute("namecardlistName",oaNamecardlist.getNamecardlistName());
        return "true";
    }



    //名片夹类名称验证
    @RequestMapping("/nameYZ")
    @ResponseBody
    public String nameYZ(OaNamecardlist oaNamecardlist,HttpSession session){
        return service.nameYZ(oaNamecardlist,session);
    }



    //添加名片夹分类
    @RequestMapping("/addNameCardList")
    @ResponseBody
    public String addNameCardList(@RequestBody OaNamecardlist oaNamecardlist, HttpSession session){
        return service.addNameCardList(oaNamecardlist, session);
    }



    //重命名
    @RequestMapping("/updateName")
    @ResponseBody
    public String updateName(OaNamecardlist oaNamecardlist){
        return service.updateName(oaNamecardlist);
    }


    //删除
    @RequestMapping("/delete/{name}")
    @ResponseBody
    public String delete(@PathVariable String name, OaNamecardlist oaNamecardlist){
        oaNamecardlist.setNamecardlistName(name);
        return service.delete(oaNamecardlist);
    }

}
